import { DataTypes, Model } from 'sequelize'
import sequelize from './db'

export interface IUserAnswer {
    id: number
    userId: number
    questionId: number
    answer: string
    score: number
}

class UserAnswer extends Model {
    declare id: number
    declare userId: number
    declare questionId: number
    declare answer: string
    declare score: number
}

UserAnswer.init(
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            autoIncrement: true,
        },
        userId: {
            type: DataTypes.INTEGER,
            comment: '用户ID'
        },
        questionId: {
            type: DataTypes.INTEGER,
            comment: '问题ID'
        },
        answer: {
            type: DataTypes.STRING,
            comment: '用户答案'
        },
        score: {
            type: DataTypes.INTEGER,
            comment: '得分'
        },
    },
    {
        // 这是其他模型参数
        sequelize, // 我们需要传递连接实例
        modelName: 'useranswer', // 我们需要选择模型名称
        paranoid: true,
    }
)

export default UserAnswer
